import socket
from io import BytesIO
def fun():
    s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # 创建一个socket   AF_INET ipv4协议  AF_INET6 ipv6协议  SOCK_STREAM  面向流的TCP协议

    # s.connect(('218.29.138.27',9319))  # 建立连接
    s.connect(('127.0.0.1',9319))

    print(s.recv(1024).decode("utf8"))

    data = ('fedc0125ab4ea3253200000005030030000000'   
    'ff0000010700000354ffffff9b0000029200000001'
    '0000001500018bcb000001000000000000000000'
    '0000000000')   # 默认发送的是16进制数据
    # data = str.encode(data)   # 字符串 编码直接转 字节
    data = bytes.fromhex(data)  # 将十六进制转化为字节形式
    print(data)



    s.send(data)

    # data = (b'fedc0125ab4ea3253200000005030030000000'  # 默认数据时 的  上报数据(bytes类型)
    #         b'ff0000010700000354ffffff9b0000029200000001'
    #         b'0000001500018bcb000001000000000000000000'
    #         b'0000000000')
    # print(data)
    # data = bytes.fromhex(bytes.decode(data))
    # print(data)
    print(s.recv(1024).decode('utf8'))
fun()
